#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>

#include "thread1.h"
#include "thread2.h"
#include "thread3.h"
#include "thread4.h"
#include "thread5.h"
#include "thread6.h"
#include "thread7.h"
#include "thread8.h"
#include "thread9.h"

// 全局变量
int g_running = 1;  // 程序运行标志

int main(int argc, char *argv[]) {
    pthread_t tid1, tid2, tid3, tid4, tid5, tid6, tid7, tid8, tid9;
    int ret;
    
    printf("程序启动，开始创建线程...\n");
    
    // 创建9个线程
    ret = pthread_create(&tid1, NULL, thread1_function, NULL);
    if (ret != 0) {
        perror("线程1创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid2, NULL, thread2_function, NULL);
    if (ret != 0) {
        perror("线程2创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid3, NULL, thread3_function, NULL);
    if (ret != 0) {
        perror("线程3创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid4, NULL, thread4_function, NULL);
    if (ret != 0) {
        perror("线程4创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid5, NULL, thread5_function, NULL);
    if (ret != 0) {
        perror("线程5创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid6, NULL, thread6_function, NULL);
    if (ret != 0) {
        perror("线程6创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid7, NULL, thread7_function, NULL);
    if (ret != 0) {
        perror("线程7创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid8, NULL, thread8_function, NULL);
    if (ret != 0) {
        perror("线程8创建失败");
        exit(EXIT_FAILURE);
    }
    
    ret = pthread_create(&tid9, NULL, thread9_function, NULL);
    if (ret != 0) {
        perror("线程9创建失败");
        exit(EXIT_FAILURE);
    }
    
    printf("所有线程已创建，主线程进入阻塞状态\n");
    
    // 等待所有线程结束（实际上永远不会结束，除非手动终止程序）
    pthread_join(tid1, NULL);
    
    return 0;
} 